package com.muyi.controller;

import com.muyi.pojo.entity.Result;
import com.muyi.pojo.entity.TagPaper;
import com.muyi.service.TagPaperService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "标签-文章模块")
@Slf4j
@CrossOrigin
@RequestMapping("/tagPaper")
@RestController
public class TagPaperController {
    @Autowired
    private TagPaperService tagPaperService;

    /**
     * 查询标签-文章数据
     * @return
     */
    @ApiOperation(value = "查询全部标签-文章")
    @GetMapping
    public Result list(){
        log.info("查询全部标签-文章数据");
        //调用service查询标签-文章数据
        List<TagPaper> TagPaperList =  tagPaperService.list();
        return Result.success(TagPaperList);
    }


    /**
     * 删除标签-文章
     * @return
     */
    @ApiOperation(value = "删除标签-文章")
    @DeleteMapping("/{tag_paper_id}")
    public Result delete(@PathVariable Integer tag_paper_id){
        log.info("根据category_id删除标签-文章:{}",tag_paper_id);
        //调用service删除标签-文章
        tagPaperService.delete(tag_paper_id);
        return Result.success();
    }


    /**
     * 新增标签-文章
     * @return
     */
    @ApiOperation(value = "新增标签-文章")
    @PostMapping
    public Result add(@RequestBody TagPaper TagPaper){
        log.info("新增标签-文章: {}" , TagPaper);
        //调用service新增标签-文章
        tagPaperService.add(TagPaper);
        return Result.success();
    }

    @ApiOperation(value = "更新标签-文章")
    @PutMapping
    public Result update(@RequestBody TagPaper TagPaper){
        log.info("更新标签-文章信息 : {}", TagPaper);
        tagPaperService.update(TagPaper);
        return Result.success();
    }

    @ApiOperation(value = "根据标签-文章id查询标签-文章")
    // 根据category_id查询标签-文章
    @GetMapping("/{tag_paper_id}")
    public Result getByTagPaperId(@PathVariable Integer tag_paper_id){
        log.info("根据tag_paper_id查询标签-文章, tag_paper_id:{}",tag_paper_id);
        TagPaper TagPaper = tagPaperService.getByTagPaperId(tag_paper_id);
        return Result.success(TagPaper);
    }
}
